import { useEffect, useState } from 'react'
import { getCompanyInfoDetailQueryBusinessInformation } from '@/api/companyDetail/BasicInfor'
import { Col, Row, Typography } from 'antd'

const BusinessInformation = (props: any) => {
  const { companyCode } = props

  const [expanded, setExpanded] = useState(false)

  const rows = 3

  const [tableList, setTableList] = useState([
    {
      label: '法定代表人',
      key: 'legalRep',
      value: '--',
      span: 12
    },
    {
      label: '登记状态',
      key: 'businessState',
      value: '--',
      span: 12
    },
    {
      label: '成立日期',
      key: 'foundDate',
      value: '--',
      span: 12
    },
    {
      label: '核准日期',
      key: 'approvalDate',
      value: '--',
      span: 12
    },
    {
      label: '注册资本',
      key: 'regcapitalAmtCal',
      value: '--',
      span: 12
    },
    {
      label: '实缴资本',
      key: 'paiedAmt',
      value: '--',
      span: 12
    },
    {
      label: '统一社会信用代码',
      key: 'uniCode',
      value: '--',
      span: 12
    },
    {
      label: '企业名称',
      key: 'companyName',
      value: '--',
      span: 12
    },
    {
      label: '组织机构代码',
      key: 'orgCode',
      value: '--',
      span: 12
    },
    {
      label: '工商注册号',
      key: 'regCode',
      value: '--',
      span: 12
    },
    {
      label: '纳税人识别号',
      key: 'taxCode',
      value: '--',
      span: 12
    },
    {
      label: '企业类型',
      key: 'companyType',
      value: '--',
      span: 12
    },
    {
      label: '营业期限',
      key: 'endDate',
      value: '--',
      span: 12
    },
    {
      label: '纳税人资质',
      key: 'taxQualified',
      value: '--',
      span: 12
    },
    {
      label: '所属行业',
      key: 'levelFirst',
      value: '--',
      span: 12
    },
    {
      label: '所属地区',
      key: 'province',
      value: '--',
      span: 12
    },
    {
      label: '登记机关',
      key: 'registerOrg',
      value: '--',
      span: 12
    },
    {
      label: '人员规模',
      key: 'companySize',
      value: '--',
      span: 12
    },
    {
      label: '参保人数',
      key: 'companyHeadcount',
      value: '--',
      span: 12
    },
    {
      label: '曾用名',
      key: 'nameBefore',
      value: '--',
      span: 12
    },
    {
      label: '进出口企业代码',
      key: 'empExpCode',
      value: '--',
      span: 12
    },
    {
      label: '英文名',
      key: 'companyNameEn',
      value: '--',
      span: 12
    },
    {
      label: '注册地址',
      key: 'regAddress',
      value: '--',
      span: 24
    },
    {
      label: '经营范围',
      key: 'businessScope',
      value: '--',
      span: 24,
      isExpand: true
    }
  ])

  function hsHandleNumDecimalPoint(value: any) {
    if (`${value}`.indexOf('.') > -1 && `${value}`.split('.')[1].length > 4) {
      value = Number(value).toFixed(4)
    }
    value = Number(value)
    return value
  }

  function hsHandleMoneyShow(value: number) {
    let money = '--'
    if (value) {
      let num: any = value
      if (num > 100000000) {
        num = (num / 100000000).toString()
        num = hsHandleNumDecimalPoint(Number(num))
        money = `${num}亿人民币`
      } else {
        num = (num / 10000).toString()
        num = hsHandleNumDecimalPoint(num)
        money = `${num}万人民币`
      }
    }
    return money
  }
  // 获取列表数据
  const getData = async () => {
    const params = {
      companyCode: companyCode || '6b3529de2f04acaa7dc1a4667f2ff530'
    }
    const res = await getCompanyInfoDetailQueryBusinessInformation(params)
    if (res.code === 200) {
      setTableList((pev: any) => {
        return pev.map((item: any) => {
          if (item.label === '注册资本') {
            return {
              ...item,
              value: hsHandleMoneyShow(res.data[item.key])
            }
          } else if (item.label === '实缴资本') {
            return {
              ...item,
              value: hsHandleMoneyShow(res.data[item.key] * 10000)
            }
          } else {
            return {
              ...item,
              value: res.data[item.key] !== null ? res.data[item.key] : '--'
            }
          }
        })
      })
    }
  }

  useEffect(() => {
    getData()
  }, [])

  return (
    <div className="BusinessInformation" id="基本信息">
      <Row gutter={[16, 16]}>
        {tableList.map((item: any, index: any) => (
          <Col span={item.span} key={index}>
            <div className="flex">
              <div className="w-178px item-label">{item.label}</div>
              <Typography.Paragraph
                className="w-100%"
                ellipsis={{
                  rows,
                  expandable: 'collapsible',
                  expanded,
                  onExpand: (_, _info) => setExpanded((c) => !c)
                }}>
                {item.value || '-'}
              </Typography.Paragraph>
            </div>
          </Col>
        ))}
      </Row>
    </div>
  )
}

export default BusinessInformation
